import Vue from 'vue'
import Vuex from 'vuex'

import {
  testExamQuery,
  testExamDelete,
  testExamAdd,
  testExamUpdate,
  testExamQueryMyExam,
  testExamGeneratePaper,
  testExamSubmitPaper,
  testExamHisQuery,
} from '@/api/admin/exam/testExam'

Vue.use(Vuex)

const state = {
  // activeName: 'manage',
  // activeRow: {},
}

const getters = {}

const actions = {
  //试题增删改查
  async testExamList({ commit }, listQuery) {
    let res = await testExamQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async testExamDel({ commit }, row) {
    let res = await testExamDelete(row.id)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async testExamADD({ commit }, data) {
    let res = await testExamAdd(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async testExamUPDATE({ commit }, data) {
    let res = await testExamUpdate(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },

  async testExamQueryMyEXAM({ commit }, listQuery) {
    let res = await testExamQueryMyExam({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //生成试卷
  async testExamGeneratePAPER({ commit }, id) {
    let res = await testExamGeneratePaper(id)
    if(!res) return false;
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //交卷
  async testExamSubmitPAPER({ commit }, data) {
    let res = await testExamSubmitPaper(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async testExamHisQUERY({ commit }, listQuery) {
    let res = await testExamHisQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
}

const mutations = {
  // SET_ACTIVENAME: (state, d) => {
  //   state.activeName = d
  // },
  // SET_ACTIVEROW: (state, d) => {
  //   state.activeRow = d
  // },
}

export default {
  state,
  getters,
  actions,
  mutations,
}
